library _;

import 'package:flutter/material.dart';
import 'package:flutter_app/Const/IFinal.dart';
import 'package:flutter_app/Model/ProductModel.dart';
import 'package:flutter_app/Page/Home/Search/main.dart';
import 'package:flutter_app/Util/App/AppUtils.dart';
import 'package:flutter_app/View/MyRefresher.dart';
import 'package:flutter_app/View/MyViews.dart';
import 'package:flutter_yfree/YFree.dart';

part 'controller.dart';

part 'view.dart';

class ProductListPage extends YPage with SingleTickerProviderStateMixin {
  ProductListPage(this.searchContent);

  String searchContent;

  var page = 1;
  AnimationController? controller_anim;
  Animation<Offset>? animation;
  double searchBarHeight = 45;
  Widget? searchBar;
  var controller_searchBar = ScrollController();
  MyRefresherController? myRefresherController;

  List<SearchMainModel> searchItems = [];
  List<ProductListSubModel> productItems = [];

  @override
  void yOnCreate() {
    controller_initData(false);
    controller_anim = AnimationController(vsync: this, duration: Duration(milliseconds: 100));
    animation = Tween(begin: Offset(0, -(searchBarHeight / yScreenSize().height)), end: Offset.zero).animate(controller_anim!);
  }

  @override
  void yOnDestory() {
    controller_anim?.dispose();
    controller_searchBar.dispose();
    searchItems.forEach((element) {
      element.controller_searchBar_inner.dispose();
    });
  }

  @override
  Widget yBuild(BuildContext context) {
    return Container(
      color: IFinal.Colors.pageBG,
      child: Column(
        children: [
          view_topBar(),
          Expanded(
            child: Column(
              children: [
                view_search(controller_searchBar),
                Expanded(
                  child: MyRefresher(
                    onCreated: (controller) => myRefresherController = controller,
                    onPull: (controller, state) => controller_initData(state == MyRefresherState.Up),
                    child: MyViews.view_productItems(yPage, productItems),
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
